package com.gizwits.opensource.appkit.yasystem;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.gizwits.opensource.appkit.R;

public class Second2Activity extends Activity {
    Button button1,button2,button3,button4,button5,button6;
    private LocalBroadcastManager localBroadcastManager;
    String data;
    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second2);
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
        button1 = (Button) findViewById(R.id.btn2);
        button2 = (Button) findViewById(R.id.btn3);
        button3 = (Button) findViewById(R.id.btn4);
        button4 = (Button) findViewById(R.id.btn5);
        button5 = (Button) findViewById(R.id.btn6);
        imageView = (ImageView) findViewById(R.id.image);

        button1.setOnClickListener(onClickListener);
        button2.setOnClickListener(onClickListener);
        button3.setOnClickListener(onClickListener);
        button4.setOnClickListener(onClickListener);
        button5.setOnClickListener(onClickListener);
        imageView.setOnClickListener(onClickListener);

    }


    ///按钮颜色改变
    private  void color(int i){
        switch (i){
            case 1:
                button1.setBackgroundColor(Color.parseColor("#FF9500"));
                button5.setBackgroundColor(Color.parseColor("#F8DC26"));
                button2.setBackgroundColor(Color.parseColor("#F8DC26"));
                break;
            case 2:
                button1.setBackgroundColor(Color.parseColor("#F8DC26"));
                button5.setBackgroundColor(Color.parseColor("#F8DC26"));
                button2.setBackgroundColor(Color.parseColor("#FF9500"));
                break;
            case 3:
                button1.setBackgroundColor(Color.parseColor("#F8DC26"));
                button5.setBackgroundColor(Color.parseColor("#FF9500"));
                button2.setBackgroundColor(Color.parseColor("#F8DC26"));
                break;
        }
    }
    Button.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.btn2:
                    data = "SymstartE";
                    retun(data);
                    break;
                case R.id.btn3:
                    data="SymstopE";
                    retun(data);
                    break;
                case R.id.btn4:
                    data="Syspeed+E";
                    retun(data);
                    break;
                case R.id.btn5:
                    data="Syspeed-E";
                    retun(data);
                    break;

                case R.id.btn6:
                    data = "SycloseautoE";
                    retun(data);
                    finish();
                    break;
                case R.id.image:
                    data = "SycloseautoE";
                    retun(data);
                    finish();
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    protected void onDestroy() {
        data = "ScloseautoE";
        retun(data);
        super.onDestroy();
    }
    public void retun(String data){
        Intent intent = new Intent("com.example.broadcasttest.LOCAL_BROADCAST");
        intent.putExtra("key",data);
        intent.putExtra("data",true);
        localBroadcastManager.sendBroadcast(intent);
    }
}

